package com.coda.service.impl;

import com.coda.constant.StatusConstant;
import com.coda.entity.LeaseTerm;
import com.coda.mapper.LeaseTermMapper;
import com.coda.service.LeaseTermService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class LeaseTermServiceImpl implements LeaseTermService {
    @Autowired
    private LeaseTermMapper leaseTermMapper;
    /**
     * 保存或修改租期信息
     * @param leaseTerm
     */
    @Override
    public void saveOrUpdate(LeaseTerm leaseTerm) {
        //判断是否有id，有：update，没有：insert
        if (leaseTerm.getId() == null){
            leaseTermMapper.insert(leaseTerm);
        }else {
            leaseTermMapper.update(leaseTerm);
        }
    }

    /**
     * 查询全部租期信息
     * @return
     */
    @Override
    public List<LeaseTerm> getAllLeaseTerm() {
        List<LeaseTerm> leaseTermList = leaseTermMapper.list();
        return leaseTermList;
    }

    /**
     * 根据id删除租期
     * @param id
     */
    @Override
    public void deleteById(Long id) {
        leaseTermMapper.delete(id);
    }
}
